﻿function game() {

    this.board = new Board();
    this.animating = true;
    this.level = new Level();
    this.content = Content();
    this.startTime = new Date();
    this.tick = 0;

    this.resetTimer = function () {
        this.startTime = new Date();
    };

    this.elapsedTime = function () {
       eTime = new Date();
       elapsed = (eTime.getTime() - this.startTime.getTime()) / 1000; 
       return elapsed;

    };

    this.initGame = function () {
        this.canvasMain = document.getElementById("canvasMain");
        this.content = new Content();
        this.level.advanceLevel();
    };


    this.stopAnimation = function () {
        this.animating = false;
    }

    this.resumeAnimation = function () {
        this.animating = true;
    }

    this.setLevel = function () {

    };


    this.draw = function () {

        this.tick++;
        if (this.tick > 100) {
            t == 0;
        }
        if ((game.level.custom.draw !== undefined) || (game.level.custom.draw !== null)) {
            game.level.custom.draw();
        }


        if (window.requestAnimationFrame) window.requestAnimationFrame(this.draw);
        // IE implementation
        else if (window.msRequestAnimationFrame) window.msRequestAnimationFrame(this.draw);
        // Firefox implementation
        else if (window.mozRequestAnimationFrame) window.mozRequestAnimationFrame(this.draw);
        // Chrome implementation
        else if (window.webkitRequestAnimationFrame) window.webkitRequestAnimationFrame(this.draw);
        // Other browsers that do not yet support feature
        else
            setTimeout(game.draw, 16);

    };

    return this;
}